const db = require("../config/mysql");

class CategoryModel {
  constructor() {
    this.db = db;
  }
  async getCategoryList() {
    let sql = `SELECT cate_id, name, cate_order 
                   FROM category 
                   WHERE cate_status = 1 
                   ORDER BY cate_order ASC, cate_id ASC`;
    try {
      let [result] = await this.db.query(sql);
      return result;
    } catch (error) {
      console.error(error.message);
      throw new Error(`无法从数据库中获取分类列表`);
    }
  }
}

module.exports = CategoryModel;
